package com.sne.airways.system.service.impl;

import com.sne.airways.basecore.service.impl.BaseServiceImpl;
import com.sne.airways.system.dao.SystemPropertiesDAO;
import com.sne.airways.system.pojo.SystemProperties;
import com.sne.airways.system.service.SystemPropertiesService;
import com.sne.airways.system.syscache.SystemPropertiesCache;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: skyline{http://my.oschina.net/skyline520}
 * Date: 12-12-11
 * Time: 下午3:28
 * To change this template use File | Settings | File Templates.
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SystemPropertiesServiceImpl extends BaseServiceImpl implements SystemPropertiesService,InitializingBean {
    @Autowired
    private SystemPropertiesCache systemPropertiesCache;
    @Autowired
    private SystemPropertiesDAO systemPropertiesDAO;
    public void initSystemProperties() {
        List<SystemProperties> systemPropertiesList = this.queryAllSystemPropertiesList();
        for (SystemProperties p : systemPropertiesList) {
            systemPropertiesCache.put(p.getKey(), p);
        }
        logger.info("[系统属性] 成功放入缓存");
    }

    /**
     * 获取所有的系统属性列表
     *
     * @return
     */
    @Override
    public List<SystemProperties> queryAllSystemPropertiesList() {
        return systemPropertiesDAO.queryAllSystemPropertiesList();
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        initSystemProperties();
    }
}
